package br.com.vilababy.sigvb.filters;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import br.com.vilababy.sigvb.SIGVBFactory;

public class SIGVBJPAFilter implements PhaseListener{

	/**
	 * @author Diego Patrick da Silva Santos
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void afterPhase(PhaseEvent evento) {
//		if(SIGVBFactory.getEM() != null && SIGVBFactory.getEM().isOpen())
//			SIGVBFactory.fecharEntityManager();
	}

	@Override
	public void beforePhase(PhaseEvent evento) {
		if(SIGVBFactory.getEM() == null || !SIGVBFactory.getEM().isOpen())
			SIGVBFactory.createEntityManager();
	}

	@Override
	public PhaseId getPhaseId() {
		return PhaseId.INVOKE_APPLICATION;
	}
	
}
